package com.cyclingAssistant.overlays;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Overlay;

import com.cyclingAssistant.project.TabMenu;
import com.cyclingAssistant.util.Geocoder;

import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.Toast;

public class TouchableOverlay extends Overlay {

	Context context;
	public EditText text;

	public TouchableOverlay(Context ctx, EditText t) {
		super(ctx);
		context = ctx;
		text = t;
	}

	@Override
	protected void draw(Canvas c, MapView osmv, boolean shadow) {

	}

	// @Override
	// public boolean onTouchEvent(MotionEvent event, MapView mapView) {
	// // ---when user lifts his finger---
	// if (event.getAction() == 0) {
	// GeoPoint p = (GeoPoint) mapView.getProjection().fromPixels((int)
	// event.getX(),
	// (int) event.getY());
	// TabMenu.tabHost.setCurrentTab(1);
	// text.setText(Geocoder.getFormattedAddress(p.getLatitudeE6()/1E6,
	// p.getLongitudeE6()/1E6));
	// TabHost tabHost = (TabHost) TabMenu.tabHost;
	// tabHost.setCurrentTab(1);
	// }
	// return false;
	// }

	@Override
	public boolean onSingleTapUp(final MotionEvent event, final MapView mapView) {
		GeoPoint p = (GeoPoint) mapView.getProjection().fromPixels(
				(int) event.getX(), (int) event.getY());
		TabMenu.tabHost.setCurrentTab(1);
		text.setText(Geocoder.getFormattedAddress(p.getLatitudeE6() / 1E6,
				p.getLongitudeE6() / 1E6));
		TabHost tabHost = (TabHost) TabMenu.tabHost;
		tabHost.setCurrentTab(1);
		return true;
	}
}
